import string
import random


def xopen(xfile_name, xmode):
    try:
        xfile = open(xfile_name, xmode, encoding='utf8')
        print(f'Opened {xfile!r}')
        xfile.close()
    except FileNotFoundError as ex:
        print(f'{xmode}: {ex!r}')


xinfix = random.randint(1, 100)
for xmode in ('r', 'r+', 'w', 'w+', 'a', 'a+'):
    xfile_name = f'nonexistent.{xinfix:03d}.{xmode}.tmp.txt'
    xopen(xfile_name, xmode)
